import axios from './base.js'
export default {
  dict: {
    data: {
      list(params = {}) {
        const { dictType, pageNum, pageSize } = params
        return axios({
          url: '/system/dict/data/list',
          params: { dictType, pageNum: pageNum || 1, pageSize: pageSize || 100 }
        })
      }
    },

    sys_user_sex(params) {
      return axios({
        url: '/system/dict/data/type/sys_user_sex',
        params
      })
    }
  },

  role: {
    list(params) {
      const { orderByColumn, pageNum, pageSize, isAsc } = params
      return axios({
        url: '/system/role/list',
        params
      })
    },
    // 查询分配权限的用户
    queryList(params) {
      const { roleId, pageNum, pageSize, userName = '', phonenumber = '' } = params;
      const query = {
        roleId,
        pageNum,
        pageSize,
        ...userName && { userName },  // 如果userName存在，才添加到查询对象中
        ...phonenumber && { phonenumber } //原因同上
      };
      return axios.get('system/role/authUser/allocatedList',
        {
          params: query
        }
      )
    },
    // 查询未分配权限的用户
    queryUnAllocateList(params) {
      const { roleId, pageNum, pageSize, userNameDialog = '', phonenumberDialog = '' } = params;
      const query = {
        roleId,
        pageNum,
        pageSize,
        // 使用扩展运算符将userNameDialog的值赋给userName
        ...userNameDialog && { userName: userNameDialog },
        // 如果phonenumberDialog存在，以同样的逻辑处理phonenumber
        ...phonenumberDialog && { phonenumber: phonenumberDialog }
      };
      return axios.get('system/role/authUser/unallocatedList',
        {
          params: query
        }
      )
    },
    changeStatus(params) {
      return axios({
        url: '/system/role/changeStatus',
        method: 'put',
        data: params
      })
    },
    // 取消权限
    cancelRight(params) {
      const { roleId, userId } = params;
      const query = {
        roleId,
        userId
      }
      return axios({
        url: '/system/role/authUser/cancel',
        method: 'put',
        data: query
      })
    },
    // 批量取消权限
    cancelRightALl(params) {
      return axios({
        url: '/system/role/authUser/cancelAll',
        method: 'put',
        data: params
      })
    },

    // 分配用户权限
    allocateRight(params) {
      return axios({
        url: '/system/role/authUser/selectAll',
        method: 'put',
        data: params
      })
    },

    treeselect(params) {
      return axios({
        url: '/system/menu/treeselect'
      })
    },
    roleMenuTreeselect(params) {
      const { roleId } = params
      return axios({
        url: '/system/menu/roleMenuTreeselect/' + roleId
      })
    },

    add(params) {
      return axios({
        url: '/system/role',
        method: 'post',
        data: params
      })
    },
    del(params) {
      let { roleId } = params
      return axios({
        url: '/system/role/' + roleId,
        method: 'DELETE',
      })
    },

    update(params) {
      return axios({
        url: '/system/role',
        method: 'put',
        data: params
      })
    },
  },

  user: {
    // 查询用户已经分配好的权限
    queryList(params) {
      const { userId } = params;
      return axios.get(`system/user/authRole/${userId}`
      )
    },
    allocateRight(params) {
      return axios({
        url: '/system/user/authRole',
        method: 'put',
        data: params
      })
    },
    changeStatus(params) {
      return axios({
        url: '/system/user/changeStatus',
        method: 'put',
        data: params
      })
    },
    getInfo() {
      return axios({
        url: '/system/user/getInfo',
      })
    },
    del(params) {
      let { userId } = params
      return axios({
        url: '/system/user/' + userId,
        method: 'DELETE',
      })
    },
    deptTree(params) {
      return axios({
        url: '/system/user/deptTree',
      })
    },
    list(params) {
      return axios({
        url: '/system/user/list',
        params
      }).then(res => {
        if (res.data.code === 200 && res.data.rows) {
        }
        return res
      })
    },
    resetPwd(params) {
      return axios({
        url: '/system/user/resetPwd',
        method: 'put',
        data: params
      })
    },
    add(params) {
      return axios({
        url: '/system/user',
        method: 'post',
        data: params
      })
    },
    update(params) {
      return axios({
        url: '/system/user',
        method: 'put',
        data: params
      })
    },
    details(params) {
      let { userId } = params
      return axios({
        url: '/system/user/' + userId,
      })
    }

  },
  dept: {
    list(params) {
      return axios({
        url: '/system/dept/list',
        params
      })
    },
    add(params) {
      return axios({
        url: '/system/dept',
        method: 'post',
        data: params
      })
    },
    update(params) {
      return axios({
        url: '/system/dept',
        method: 'put',
        data: params
      })
    },
    del(params) {
      let { deptId } = params
      return axios({
        url: '/system/dept/' + deptId,
        method: 'DELETE',
      })
    },
  },
  menu: {
    list(params) {
      return axios({
        url: '/system/menu/list',
        params
      })
    },
    add(params) {
      return axios({
        url: '/system/menu',
        method: 'post',
        data: params
      })
    },
    update(params) {
      return axios({
        url: '/system/menu',
        method: 'put',
        data: params
      })
    },
    del(params) {
      let { menuId } = params
      return axios({
        url: '/system/menu/' + menuId,
        method: 'DELETE',
      })
    },
  },
  teacherAudit: {
    list(params) {
      return axios({
        url: '/school/teacherAudit/list',
        params
      })
    },
    audit(params) {
      return axios({
        url: '/school/teacherAudit',
        method: 'put',
        data: params
      })
    },
  },
  schoolClass: {
    getStage(params) {
      return axios({
        url: '/school/schoolClass/getStage',
        params
      })
    },
    list(params) {
      return axios({
        url: '/school/schoolClass/list',
        params
      })
    },
    update(params) {
      return axios({
        url: '/school/schoolClass',
        method: 'put',
        data: params
      })
    },
    del(params) {
      let { ids } = params
      return axios({
        url: '/school/schoolClass/' + ids,
        method: 'DELETE',
      })
    },
    student(params) {
      return axios({
        url: '/school/classConUser/listMainStudent',
        params
      })
    },
  }
}